/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.anniversary.domain;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import me.zhengjie.base.BaseEntity;
import me.zhengjie.modules.system.domain.User;

import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Objects;

/**
* @website https://el-admin.vip
* @description /
* @author Jiayin Wei
* @date 2020-07-27
**/
@Entity
@Getter
@Setter
@Table(name="gzmu_ann_message")
public class Message extends BaseEntity implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    @ApiModelProperty(value = "ID", hidden = true)
    private Long id;

    @Column(name = "name",nullable = false)
    @NotBlank
    @ApiModelProperty(value = "标题")
    private String name;

    @Column(name = "user_id")
    @ApiModelProperty(value = "发布者ID")
    private Long userId;

    @OneToOne
    @JoinColumn(name = "user_id", referencedColumnName = "user_id", insertable = false, updatable = false)
    @ApiModelProperty(value = "发布者")
    private User publisher;

    @Column(name = "user_type")
    @ApiModelProperty(value = "发布者类型（0：教职工校友，1：学生校友）")
    private Integer userType;

    @Column(name = "content")
    @ApiModelProperty(value = "留言板内容（通常都是短消息，不超过1024个字符）")
    private String content;

    @Column(name = "verify_status")
    @ApiModelProperty(value = "审核状态（0：待审核，1：审核通过，2：审核未通过）")
    private Integer verifyStatus;

    @Column(name = "reviewer_id")
    @ApiModelProperty(value = "审核者ID")
    private Long reviewerId;

    @OneToOne
    @JoinColumn(name = "reviewer_id", referencedColumnName = "user_id", insertable = false, updatable = false)
    @ApiModelProperty(value = "审核者")
    private User reviewer;

    @Column(name = "review_time")
    @ApiModelProperty(value = "审核时间")
    private Timestamp reviewTime;

    @Column(name = "sort")
    @ApiModelProperty(value = "排序")
    private Integer sort;

    @Column(name = "remark")
    @ApiModelProperty(value = "备注")
    private String remark;

    @Column(name = "is_enable")
    @ApiModelProperty(value = "是否启用")
    private Boolean isEnable;

    public void copy(Message source){
        BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, name);
    }
}